<?php
namespace app\atxunda\controller;
use think\Controller;
use think\Db; 
use think\Cookie; 
use think\Request;

class Order extends Common
{
	public function index(){
        $admin = $this->admin;
        $where = 1;
        $admin_id = $admin['admin_id'];
        $admin_data = Db::table('admin')->field('role_id')->where('admin_id',$admin_id)->find();
        $request = Request::instance();
        $param = $request->param();
        $start_time = $request->param('start_time');
        $end_time = $request->param('end_time');
        $phone = $request->param('phone');
        $orderid = $request->param('orderid');
        if(!empty($start_time)){
        	$this->assign('start_time',$start_time);
            $start_time = strtotime($start_time);
            $where .= " and UNIX_TIMESTAMP(update_time)>=$start_time";
        }
        if(!empty($end_time)){
        	$this->assign('end_time',$end_time);
            $end_time = strtotime($end_time);
            $where .= " and UNIX_TIMESTAMP(update_time)<=$end_time";
        }
        if(!empty($phone)){
            $phone = encrypt1($phone,config('sha256'));
            $where .= " and know_phone|know_email='$phone'";
        }
        if(!empty($orderid)){
            $where .= " and order_id='$orderid'";
        }
		$data = Db::table('order')
			->field('order.*,know_user.know_phone,nav_name,know_email')
			->join('know_user','know_user.know_user_id=order.user_id')
			->join('nav','nav.nav_id=order.nav_id')
			->where($where)->order('input_time desc')->paginate(20);
        $this->assign('param',$param);
		$this->assign('data',$data);
		return $this->fetch();
	}
}